#include <QStringListModel>

#include "data.h"
#include "insertdatadialog.h"

InsertDataDialog::InsertDataDialog( QWidget * parent) 
	: QDialog(parent)
{
	setupUi(this);
	data = new Data;
	
	subjectWidget = new InsertDataWidget(data->subjectList);
	QVBoxLayout *subjectLayout = new QVBoxLayout;
	subjectLayout->addWidget( subjectWidget );
	subjectGBox->setLayout( subjectLayout );
	
	placeWidget = new InsertDataWidget(data->placeList);
	QVBoxLayout *placeLayout = new QVBoxLayout;
	placeLayout->addWidget( placeWidget );
	placeGBox->setLayout( placeLayout );
	
	teacherWidget = new InsertDataWidget(data->teacherList);
	QVBoxLayout *teacherLayout = new QVBoxLayout;
	teacherLayout->addWidget( teacherWidget );
	teacherGBox->setLayout( teacherLayout );
	
	connect(saveButton,SIGNAL(clicked()),this,SLOT(save()));
	connect(cancelButton,SIGNAL(clicked()),this,SLOT(cancel()));
}

void InsertDataDialog::save()
{
	data->subjectList = subjectWidget->model->stringList();
	data->placeList = placeWidget->model->stringList();
	data->teacherList = teacherWidget->model->stringList();
	data->writeFile();
	close();
}

void InsertDataDialog::cancel()
{
	subjectWidget->revert();
	placeWidget->revert();
	teacherWidget->revert();
	
	close();
}
